<?php
/**
 * @Author: Ron Chen
 * @Date:   2017-03-25 00:56:58
 * @Last Modified by:   Ron Chen
 * @Last Modified time: 2017-03-25 22:09:42
 */
namespace app\models;

use Yii;

/**
 * * [************已经弃用************]
 *
 * @property integer $id
 * @property string $project_code
 * @property string $plan_code
 * @property string $plan_name
 * @property string $benifit_code
 * @property string $benifit_name
 * @property string $benifit_amount
 * @property string $benifit_currency
 */
class InsurancePerson extends \yii\db\ActiveRecord
{
	const PERSON_USER_RELATION_FM = 1;
	const PERSON_USER_RELATION_ZN = 2;
	const PERSON_USER_RELATION_PY = 3;
	const PERSON_USER_RELATION_XD = 4;
	const PERSON_USER_RELATION_JM = 5;
	const PERSON_USER_RELATION_QT = 6;

	public static $user_relation = [
		self::PERSON_USER_RELATION_FM => '父母',
		self::PERSON_USER_RELATION_ZN => '子女',
		self::PERSON_USER_RELATION_PY => '朋友',
		self::PERSON_USER_RELATION_XD => '兄弟',
		self::PERSON_USER_RELATION_JM => '姐妹',
		self::PERSON_USER_RELATION_QT => '其他', 
	];

	
	const USER_STATUS_SUCCESS = 1;
	const USER_STATUS_FAILD   = 0;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'insurance_person';
    }


    /**
     * 初始化用户操作
     */
    public static function initRecord($param){
    	$user_id = isset($param["user_id"]) ? $param["user_id"] : 0;
    	$project_id = isset($param["project_id"]) ? $param["project_id"] : 0;
    	
		$userInfo = new static();
		$userInfo->user_id = $user_id;
		$userInfo->project_id = $project_id;
		$userInfo->ctime  = time();
    	
    	if (isset($param['name']) && $param['name']) {
    		$userInfo->name = $param['name'];
    	}
    	if (isset($param['id_type']) && $param['id_type']) {
    		$userInfo->id_type = $param['id_type'];
    	}
    	if (isset($param['id_card']) && $param['id_card']) {
    		$userInfo->id_card = $param['id_card'];
    	}
    	if (isset($param['birthday']) && $param['birthday']) {
    		$userInfo->birthday = $param['birthday'];
    	}
    	if (isset($param['sex']) && $param['sex'] && in_array($param['sex'], self::$user_info_sex)) {
    		$userInfo->sex = $param['sex'];
    	}
    	if (isset($param['phone']) && $param['phone']) {
    		$userInfo->phone = $param['phone'];
    	}
    	if (isset($param['email']) && $param['email']) {
    		$userInfo->email = $param['email'];
    	}

    	$userInfo->status = self::USER_STATUS_SUCCESS;
    	$userInfo->utime  = time();

    	if ($userInfo->save()) {
    		return $userInfo->attributes['id'];
    	}
    	return false;
    }
    
}
